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" |
| 39 | |
Alexandre Lision | 53428a5 | 2015-03-20 17:59:00 -0400 | [diff] [blame] | 40 | // We disabled IAX protocol for now, so don't show it to the user |
| 41 | class ActiveProtocolModel : public QSortFilterProxyModel |
| 42 | { |
| 43 | public: |
| 44 | ActiveProtocolModel(QAbstractItemModel* parent) : QSortFilterProxyModel(parent) |
| 45 | { |
| 46 | setSourceModel(parent); |
| 47 | } |
| 48 | virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const |
| 49 | { |
| 50 | return sourceModel()->index(source_row,0,source_parent).flags() & Qt::ItemIsEnabled; |
| 51 | } |
| 52 | }; |
| 53 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 54 | @interface AccountsVC () |
| 55 | @property (assign) IBOutlet NSPopUpButton *protocolList; |
| 56 | |
| 57 | @property (assign) IBOutlet NSTabView *configPanels; |
| 58 | @property (retain) IBOutlet NSTabViewItem *generalTabItem; |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 59 | @property (retain) IBOutlet NSTabViewItem *mediaTabItem; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 60 | @property (retain) IBOutlet NSTabViewItem *advancedTabItem; |
| 61 | @property (retain) IBOutlet NSTabViewItem *securityTabItem; |
| 62 | @property (retain) IBOutlet NSTabViewItem *ringTabItem; |
| 63 | |
| 64 | @property QNSTreeController *treeController; |
Alexandre Lision | 53428a5 | 2015-03-20 17:59:00 -0400 | [diff] [blame] | 65 | @property ActiveProtocolModel* proxyProtocolModel; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 66 | @property (assign) IBOutlet NSOutlineView *accountsListView; |
| 67 | @property (assign) IBOutlet NSTabView *accountDetailsView; |
| 68 | |
| 69 | @property AccRingVC* ringVC; |
| 70 | @property AccGeneralVC* generalVC; |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 71 | @property AccMediaVC* audioVC; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 72 | @property AccAdvancedVC* advancedVC; |
| 73 | @property AccSecurityVC* securityVC; |
| 74 | |
| 75 | @end |
| 76 | |
| 77 | @implementation AccountsVC |
| 78 | @synthesize protocolList; |
| 79 | @synthesize configPanels; |
| 80 | @synthesize generalTabItem; |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 81 | @synthesize mediaTabItem; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 82 | @synthesize advancedTabItem; |
| 83 | @synthesize securityTabItem; |
| 84 | @synthesize ringTabItem; |
| 85 | @synthesize accountsListView; |
| 86 | @synthesize accountDetailsView; |
| 87 | @synthesize treeController; |
Alexandre Lision | 53428a5 | 2015-03-20 17:59:00 -0400 | [diff] [blame] | 88 | @synthesize proxyProtocolModel; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 89 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame^] | 90 | NSInteger const TAG_CHECK = 100; |
| 91 | NSInteger const TAG_NAME = 200; |
| 92 | NSInteger const TAG_STATUS = 300; |
| 93 | NSInteger const TAG_TYPE = 400; |
| 94 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 95 | - (void)awakeFromNib |
| 96 | { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 97 | treeController = [[QNSTreeController alloc] initWithQModel:&AccountModel::instance()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 98 | [treeController setAvoidsEmptySelection:NO]; |
| 99 | [treeController setAlwaysUsesMultipleValuesMarker:YES]; |
| 100 | [treeController setChildrenKeyPath:@"children"]; |
| 101 | |
| 102 | [accountsListView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil]; |
| 103 | [accountsListView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil]; |
| 104 | [accountsListView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil]; |
| 105 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 106 | QObject::connect(&AccountModel::instance(), |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 107 | &QAbstractItemModel::dataChanged, |
| 108 | [=](const QModelIndex &topLeft, const QModelIndex &bottomRight) { |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 109 | [accountsListView reloadDataForRowIndexes: |
| 110 | [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(topLeft.row(), bottomRight.row() + 1)] |
| 111 | columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, accountsListView.tableColumns.count)]]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 112 | }); |
| 113 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame^] | 114 | QObject::connect(AccountModel::instance().selectionModel(), |
| 115 | &QItemSelectionModel::currentChanged, |
| 116 | [=](const QModelIndex ¤t, const QModelIndex &previous) { |
| 117 | [accountDetailsView setHidden:!current.isValid()]; |
| 118 | if(!current.isValid()) { |
| 119 | [accountsListView deselectAll:nil]; |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | [treeController setSelectionQModelIndex:current]; |
| 124 | }); |
| 125 | |
| 126 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 127 | AccountModel::instance().selectionModel()->clearCurrentIndex(); |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 128 | |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 129 | proxyProtocolModel = new ActiveProtocolModel(AccountModel::instance().protocolModel()); |
| 130 | QModelIndex qProtocolIdx = AccountModel::instance().protocolModel()->selectionModel()->currentIndex(); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 131 | [self.protocolList addItemWithTitle: |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 132 | AccountModel::instance().protocolModel()->data(qProtocolIdx, Qt::DisplayRole).toString().toNSString()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 133 | |
| 134 | self.generalVC = [[AccGeneralVC alloc] initWithNibName:@"AccGeneral" bundle:nil]; |
| 135 | [[self.generalVC view] setFrame:[self.generalTabItem.view frame]]; |
| 136 | [[self.generalVC view] setBounds:[self.generalTabItem.view bounds]]; |
| 137 | [self.generalTabItem setView:self.generalVC.view]; |
| 138 | |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 139 | self.audioVC = [[AccMediaVC alloc] initWithNibName:@"AccMedia" bundle:nil]; |
| 140 | [[self.audioVC view] setFrame:[self.mediaTabItem.view frame]]; |
| 141 | [[self.audioVC view] setBounds:[self.mediaTabItem.view bounds]]; |
| 142 | [self.mediaTabItem setView:self.audioVC.view]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 143 | |
| 144 | self.advancedVC = [[AccAdvancedVC alloc] initWithNibName:@"AccAdvanced" bundle:nil]; |
| 145 | [[self.advancedVC view] setFrame:[self.advancedTabItem.view frame]]; |
| 146 | [[self.advancedVC view] setBounds:[self.advancedTabItem.view bounds]]; |
| 147 | [self.advancedTabItem setView:self.advancedVC.view]; |
| 148 | |
| 149 | self.securityVC = [[AccSecurityVC alloc] initWithNibName:@"AccSecurity" bundle:nil]; |
| 150 | [[self.securityVC view] setFrame:[self.securityTabItem.view frame]]; |
| 151 | [[self.securityVC view] setBounds:[self.securityTabItem.view bounds]]; |
| 152 | [self.securityTabItem setView:self.securityVC.view]; |
| 153 | |
| 154 | self.ringVC = [[AccRingVC alloc] initWithNibName:@"AccRing" bundle:nil]; |
| 155 | [[self.ringVC view] setFrame:[self.ringTabItem.view frame]]; |
| 156 | [[self.ringVC view] setBounds:[self.ringTabItem.view bounds]]; |
| 157 | [self.ringTabItem setView:self.ringVC.view]; |
| 158 | } |
| 159 | |
Alexandre Lision | 54b0fae | 2015-08-04 15:19:01 -0400 | [diff] [blame] | 160 | - (void) dealloc |
| 161 | { |
| 162 | delete proxyProtocolModel; |
| 163 | } |
| 164 | |
Alexandre Lision | b7ee3ed | 2015-03-20 18:04:35 -0400 | [diff] [blame] | 165 | - (IBAction)moveUp:(id)sender { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 166 | AccountModel::instance().moveUp(); |
Alexandre Lision | b7ee3ed | 2015-03-20 18:04:35 -0400 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | - (IBAction)moveDown:(id)sender { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 170 | AccountModel::instance().moveDown(); |
Alexandre Lision | b7ee3ed | 2015-03-20 18:04:35 -0400 | [diff] [blame] | 171 | } |
| 172 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 173 | - (IBAction)removeAccount:(id)sender { |
| 174 | |
| 175 | if(treeController.selectedNodes.count > 0) { |
| 176 | QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 177 | AccountModel::instance().remove(qIdx); |
| 178 | AccountModel::instance().save(); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | - (IBAction)addAccount:(id)sender { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 182 | QModelIndex qIdx = AccountModel::instance().protocolModel()->selectionModel()->currentIndex(); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 183 | |
Alexandre Lision | 81c9721 | 2015-06-17 15:51:53 -0400 | [diff] [blame] | 184 | auto newAccName = [[NSString alloc] initWithFormat:@"%@ account", |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 185 | AccountModel::instance().protocolModel()->data(qIdx, Qt::DisplayRole).toString().toNSString(), nil]; |
| 186 | auto acc = AccountModel::instance().add([newAccName UTF8String], qIdx); |
Alexandre Lision | a1f07bf | 2015-07-28 10:30:55 -0400 | [diff] [blame] | 187 | acc->setDisplayName(acc->alias()); |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 188 | AccountModel::instance().save(); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | - (IBAction)protocolSelectedChanged:(id)sender { |
| 192 | |
| 193 | int index = [sender indexOfSelectedItem]; |
Alexandre Lision | 53428a5 | 2015-03-20 17:59:00 -0400 | [diff] [blame] | 194 | QModelIndex proxyIdx = proxyProtocolModel->index(index, 0); |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 195 | AccountModel::instance().protocolModel()->selectionModel()->setCurrentIndex( |
Alexandre Lision | 53428a5 | 2015-03-20 17:59:00 -0400 | [diff] [blame] | 196 | proxyProtocolModel->mapToSource(proxyIdx), QItemSelectionModel::ClearAndSelect); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 197 | |
| 198 | } |
| 199 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 200 | - (void) setupSIPPanels |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 201 | { |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 202 | // Start by removing all tabs |
| 203 | for(NSTabViewItem* item in configPanels.tabViewItems) { |
| 204 | [configPanels removeTabViewItem:item]; |
| 205 | } |
| 206 | |
| 207 | [configPanels insertTabViewItem:generalTabItem atIndex:0]; |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 208 | [configPanels insertTabViewItem:mediaTabItem atIndex:1]; |
| 209 | [configPanels insertTabViewItem:advancedTabItem atIndex:2]; |
| 210 | [configPanels insertTabViewItem:securityTabItem atIndex:3]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 211 | } |
| 212 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 213 | - (void) setupIAXPanels |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 214 | { |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 215 | // Start by removing all tabs |
| 216 | for(NSTabViewItem* item in configPanels.tabViewItems) { |
| 217 | [configPanels removeTabViewItem:item]; |
| 218 | } |
| 219 | |
| 220 | [configPanels insertTabViewItem:generalTabItem atIndex:0]; |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 221 | [configPanels insertTabViewItem:mediaTabItem atIndex:1]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 222 | } |
| 223 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 224 | - (void) setupRINGPanels |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 225 | { |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 226 | // Start by removing all tabs |
| 227 | for(NSTabViewItem* item in configPanels.tabViewItems) { |
| 228 | [configPanels removeTabViewItem:item]; |
| 229 | } |
| 230 | |
| 231 | [configPanels insertTabViewItem:ringTabItem atIndex:0]; |
Alexandre Lision | e4d61cb | 2016-02-10 09:26:24 -0500 | [diff] [blame] | 232 | [configPanels insertTabViewItem:mediaTabItem atIndex:1]; |
| 233 | [configPanels insertTabViewItem:advancedTabItem atIndex:2]; |
Alexandre Lision | 9ddfd8d | 2015-08-10 15:11:16 -0400 | [diff] [blame] | 234 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 235 | } |
| 236 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame^] | 237 | - (IBAction)toggleAccount:(NSButton*)sender { |
| 238 | NSInteger row = [accountsListView rowForView:sender]; |
| 239 | auto accountToToggle = AccountModel::instance().getAccountByModelIndex(AccountModel::instance().index(row)); |
| 240 | accountToToggle->setEnabled(sender.state); |
| 241 | accountToToggle << Account::EditAction::SAVE; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | #pragma mark - NSOutlineViewDelegate methods |
| 245 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 246 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item; |
| 247 | { |
| 248 | return YES; |
| 249 | } |
| 250 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame^] | 251 | - (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 252 | { |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame^] | 253 | return [outlineView makeViewWithIdentifier:@"HoverRowView" owner:nil]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame^] | 256 | - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 257 | { |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame^] | 258 | NSTableView* result = [outlineView makeViewWithIdentifier:@"AccountView" owner:self]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 259 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 260 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
| 261 | if(!qIdx.isValid()) |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame^] | 262 | return result; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 263 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame^] | 264 | NSTextField* nameLabel = [result viewWithTag:TAG_NAME]; |
| 265 | NSTextField* stateLabel = [result viewWithTag:TAG_STATUS]; |
| 266 | NSButton* checkButton = [result viewWithTag:TAG_CHECK]; |
| 267 | NSTextField* typeLabel = [result viewWithTag:TAG_TYPE]; |
Alexandre Lision | 0ab4608 | 2015-08-11 12:10:21 -0400 | [diff] [blame] | 268 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame^] | 269 | auto account = AccountModel::instance().getAccountByModelIndex(qIdx); |
| 270 | auto humanState = account->toHumanStateName(); |
| 271 | |
| 272 | [nameLabel setStringValue:account->alias().toNSString()]; |
| 273 | [stateLabel setStringValue:humanState.toNSString()]; |
| 274 | [checkButton setHidden:AccountModel::instance().ip2ip()->index() == qIdx]; |
| 275 | |
| 276 | switch (account->protocol()) { |
| 277 | case Account::Protocol::SIP: |
| 278 | [typeLabel setStringValue:@"SIP"]; |
| 279 | break; |
| 280 | case Account::Protocol::IAX: |
| 281 | [typeLabel setStringValue:@"IAX"]; |
| 282 | break; |
| 283 | case Account::Protocol::RING: |
| 284 | [typeLabel setStringValue:@"RING"]; |
| 285 | break; |
| 286 | default: |
| 287 | break; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 288 | } |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame^] | 289 | |
| 290 | switch (account->registrationState()) { |
| 291 | case Account::RegistrationState::READY: |
| 292 | [stateLabel setTextColor:[NSColor colorWithCalibratedRed:116/255.0 green:179/255.0 blue:93/255.0 alpha:1.0]]; |
| 293 | break; |
| 294 | case Account::RegistrationState::TRYING: |
| 295 | [stateLabel setTextColor:[NSColor redColor]]; |
| 296 | break; |
| 297 | case Account::RegistrationState::UNREGISTERED: |
| 298 | [stateLabel setTextColor:[NSColor blackColor]]; |
| 299 | break; |
| 300 | case Account::RegistrationState::ERROR: |
| 301 | [stateLabel setTextColor:[NSColor redColor]]; |
| 302 | break; |
| 303 | default: |
| 304 | [stateLabel setTextColor:[NSColor blackColor]]; |
| 305 | break; |
| 306 | } |
| 307 | |
| 308 | [checkButton setState:qIdx.data(Qt::CheckStateRole).value<BOOL>()]; |
| 309 | |
| 310 | return result; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 311 | } |
| 312 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 313 | - (void)outlineViewSelectionDidChange:(NSNotification *)notification |
| 314 | { |
| 315 | // ask the tree controller for the current selection |
| 316 | if([[treeController selectedNodes] count] > 0) { |
Alexandre Lision | 81c9721 | 2015-06-17 15:51:53 -0400 | [diff] [blame] | 317 | auto qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 318 | //Update details view |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 319 | auto acc = AccountModel::instance().getAccountByModelIndex(qIdx); |
| 320 | AccountModel::instance().selectionModel()->setCurrentIndex(qIdx, QItemSelectionModel::ClearAndSelect); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 321 | |
Alexandre Lision | 0c56cb6 | 2016-02-12 18:04:08 -0500 | [diff] [blame^] | 322 | switch (acc->protocol()) { |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 323 | case Account::Protocol::SIP: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 324 | [self setupSIPPanels]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 325 | break; |
| 326 | case Account::Protocol::IAX: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 327 | [self setupIAXPanels]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 328 | break; |
| 329 | case Account::Protocol::RING: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 330 | [self setupRINGPanels]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 331 | break; |
| 332 | default: |
| 333 | break; |
| 334 | } |
| 335 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 336 | [self.accountDetailsView setHidden:NO]; |
| 337 | } else { |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 338 | AccountModel::instance().selectionModel()->clearCurrentIndex(); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
| 342 | #pragma mark - NSMenuDelegate methods |
| 343 | |
| 344 | - (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:(NSInteger)index shouldCancel:(BOOL)shouldCancel |
| 345 | { |
Alexandre Lision | 53428a5 | 2015-03-20 17:59:00 -0400 | [diff] [blame] | 346 | QModelIndex proxyIdx = proxyProtocolModel->index(index, 0); |
Alexandre Lision | d3aa3ad | 2015-10-23 14:28:41 -0400 | [diff] [blame] | 347 | QModelIndex qIdx = AccountModel::instance().protocolModel()->index(proxyProtocolModel->mapToSource(proxyIdx).row()); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 348 | [item setTitle:qIdx.data(Qt::DisplayRole).toString().toNSString()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 349 | |
| 350 | return YES; |
| 351 | } |
| 352 | |
| 353 | - (NSInteger)numberOfItemsInMenu:(NSMenu *)menu |
| 354 | { |
Alexandre Lision | 53428a5 | 2015-03-20 17:59:00 -0400 | [diff] [blame] | 355 | return proxyProtocolModel->rowCount(); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 356 | } |
| 357 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 358 | @end |