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