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