Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2015 Savoir-Faire Linux Inc. |
| 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 | 53428a5 | 2015-03-20 17:59:00 -0400 | [diff] [blame] | 126 | self.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 | b7ee3ed | 2015-03-20 18:04:35 -0400 | [diff] [blame] | 162 | - (IBAction)moveUp:(id)sender { |
| 163 | AccountModel::instance()->moveUp(); |
| 164 | } |
| 165 | |
| 166 | - (IBAction)moveDown:(id)sender { |
| 167 | AccountModel::instance()->moveDown(); |
| 168 | } |
| 169 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 170 | - (IBAction)removeAccount:(id)sender { |
| 171 | |
| 172 | if(treeController.selectedNodes.count > 0) { |
| 173 | QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
| 174 | AccountModel::instance()->remove(qIdx); |
Alexandre Lision | b7ee3ed | 2015-03-20 18:04:35 -0400 | [diff] [blame] | 175 | AccountModel::instance()->save(); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | - (IBAction)addAccount:(id)sender { |
| 179 | QModelIndex qIdx = AccountModel::instance()->protocolModel()->selectionModel()->currentIndex(); |
| 180 | |
Alexandre Lision | 81c9721 | 2015-06-17 15:51:53 -0400 | [diff] [blame^] | 181 | auto newAccName = [[NSString alloc] initWithFormat:@"%@ account", |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 182 | AccountModel::instance()->protocolModel()->data(qIdx, Qt::DisplayRole).toString().toNSString(), nil]; |
Alexandre Lision | 81c9721 | 2015-06-17 15:51:53 -0400 | [diff] [blame^] | 183 | AccountModel::instance()->add([newAccName UTF8String], qIdx); |
Alexandre Lision | b7ee3ed | 2015-03-20 18:04:35 -0400 | [diff] [blame] | 184 | AccountModel::instance()->save(); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | - (IBAction)protocolSelectedChanged:(id)sender { |
| 188 | |
| 189 | int index = [sender indexOfSelectedItem]; |
Alexandre Lision | 53428a5 | 2015-03-20 17:59:00 -0400 | [diff] [blame] | 190 | QModelIndex proxyIdx = proxyProtocolModel->index(index, 0); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 191 | AccountModel::instance()->protocolModel()->selectionModel()->setCurrentIndex( |
Alexandre Lision | 53428a5 | 2015-03-20 17:59:00 -0400 | [diff] [blame] | 192 | proxyProtocolModel->mapToSource(proxyIdx), QItemSelectionModel::ClearAndSelect); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 193 | |
| 194 | } |
| 195 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 196 | - (void) setupSIPPanels |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 197 | { |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 198 | // Start by removing all tabs |
| 199 | for(NSTabViewItem* item in configPanels.tabViewItems) { |
| 200 | [configPanels removeTabViewItem:item]; |
| 201 | } |
| 202 | |
| 203 | [configPanels insertTabViewItem:generalTabItem atIndex:0]; |
| 204 | [configPanels insertTabViewItem:audioTabItem atIndex:1]; |
| 205 | [configPanels insertTabViewItem:videoTabItem atIndex:2]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 206 | [configPanels insertTabViewItem:advancedTabItem atIndex:3]; |
| 207 | [configPanels insertTabViewItem:securityTabItem atIndex:4]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 208 | } |
| 209 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 210 | - (void) setupIAXPanels |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 211 | { |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 212 | // Start by removing all tabs |
| 213 | for(NSTabViewItem* item in configPanels.tabViewItems) { |
| 214 | [configPanels removeTabViewItem:item]; |
| 215 | } |
| 216 | |
| 217 | [configPanels insertTabViewItem:generalTabItem atIndex:0]; |
| 218 | [configPanels insertTabViewItem:audioTabItem atIndex:1]; |
| 219 | [configPanels insertTabViewItem:videoTabItem atIndex:2]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 220 | } |
| 221 | |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 222 | - (void) setupRINGPanels |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 223 | { |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 224 | // Start by removing all tabs |
| 225 | for(NSTabViewItem* item in configPanels.tabViewItems) { |
| 226 | [configPanels removeTabViewItem:item]; |
| 227 | } |
| 228 | |
| 229 | [configPanels insertTabViewItem:ringTabItem atIndex:0]; |
| 230 | [configPanels insertTabViewItem:audioTabItem atIndex:1]; |
| 231 | [configPanels insertTabViewItem:videoTabItem atIndex:2]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | - (IBAction)toggleAccount:(NSOutlineView*)sender { |
| 235 | |
| 236 | if([sender clickedColumn] < 0) |
| 237 | return; |
| 238 | |
| 239 | NSTableColumn* col = [sender.tableColumns objectAtIndex:[sender clickedColumn]]; |
| 240 | if([col.identifier isEqualToString:COLUMNID_ENABLE]) { |
| 241 | NSInteger row = [sender clickedRow]; |
| 242 | QModelIndex accIdx = AccountModel::instance()->index(row); |
| 243 | Account* toToggle = AccountModel::instance()->getAccountByModelIndex(accIdx); |
| 244 | NSButtonCell *cell = [col dataCellForRow:row]; |
| 245 | toToggle->setEnabled(cell.state == NSOnState ? NO : YES); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 246 | toToggle << Account::EditAction::SAVE; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
| 250 | #pragma mark - NSOutlineViewDelegate methods |
| 251 | |
| 252 | // ------------------------------------------------------------------------------- |
| 253 | // shouldSelectItem:item |
| 254 | // ------------------------------------------------------------------------------- |
| 255 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item; |
| 256 | { |
| 257 | return YES; |
| 258 | } |
| 259 | |
| 260 | // ------------------------------------------------------------------------------- |
| 261 | // dataCellForTableColumn:tableColumn:item |
| 262 | // ------------------------------------------------------------------------------- |
| 263 | - (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 264 | { |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 265 | NSCell *returnCell; |
| 266 | |
| 267 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
| 268 | // Prevent user from enabling/disabling IP2IP account |
| 269 | if ([[tableColumn identifier] isEqualToString:COLUMNID_ENABLE] && |
| 270 | AccountModel::instance()->ip2ip()->index() == qIdx) { |
| 271 | |
Alexandre Lision | 81c9721 | 2015-06-17 15:51:53 -0400 | [diff] [blame^] | 272 | return [[NSCell alloc] init]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 273 | } else { |
Alexandre Lision | 81c9721 | 2015-06-17 15:51:53 -0400 | [diff] [blame^] | 274 | return [tableColumn dataCell]; |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 275 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | // ------------------------------------------------------------------------------- |
| 279 | // textShouldEndEditing:fieldEditor |
| 280 | // ------------------------------------------------------------------------------- |
| 281 | - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor |
| 282 | { |
| 283 | if ([[fieldEditor string] length] == 0) |
| 284 | { |
| 285 | // don't allow empty node names |
| 286 | return NO; |
| 287 | } |
| 288 | else |
| 289 | { |
| 290 | return YES; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | // ------------------------------------------------------------------------------- |
| 295 | // shouldEditTableColumn:tableColumn:item |
| 296 | // |
| 297 | // Decide to allow the edit of the given outline view "item". |
| 298 | // ------------------------------------------------------------------------------- |
| 299 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 300 | { |
| 301 | return NO; |
| 302 | } |
| 303 | |
| 304 | // ------------------------------------------------------------------------------- |
| 305 | // outlineView:willDisplayCell:forTableColumn:item |
| 306 | // ------------------------------------------------------------------------------- |
| 307 | - (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 308 | { |
| 309 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
| 310 | if(!qIdx.isValid()) |
| 311 | return; |
| 312 | |
| 313 | if ([[tableColumn identifier] isEqualToString:COLUMNID_NAME]) |
| 314 | { |
| 315 | cell.title = AccountModel::instance()->data(qIdx, Qt::DisplayRole).toString().toNSString(); |
| 316 | } else if([[tableColumn identifier] isEqualToString:COLUMNID_STATE]) { |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 317 | NSTextFieldCell* stateCell = cell; |
| 318 | Account::RegistrationState state = qvariant_cast<Account::RegistrationState>(qIdx.data((int)Account::Role::RegistrationState)); |
Alexandre Lision | 2528d80 | 2015-03-20 18:05:06 -0400 | [diff] [blame] | 319 | switch (state) { |
| 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]]; |
| 322 | [stateCell setTitle:@"Ready"]; |
Alexandre Lision | 2528d80 | 2015-03-20 18:05:06 -0400 | [diff] [blame] | 323 | break; |
| 324 | case Account::RegistrationState::TRYING: |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 325 | [stateCell setTextColor:[NSColor redColor]]; |
| 326 | [stateCell setTitle:@"Trying..."]; |
Alexandre Lision | 2528d80 | 2015-03-20 18:05:06 -0400 | [diff] [blame] | 327 | break; |
| 328 | case Account::RegistrationState::UNREGISTERED: |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 329 | [stateCell setTextColor:[NSColor blackColor]]; |
| 330 | [stateCell setTitle:@"Unregistered"]; |
Alexandre Lision | 2528d80 | 2015-03-20 18:05:06 -0400 | [diff] [blame] | 331 | break; |
| 332 | case Account::RegistrationState::ERROR: |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 333 | [stateCell setTextColor:[NSColor redColor]]; |
| 334 | [stateCell setTitle:@"Error"]; |
Alexandre Lision | 2528d80 | 2015-03-20 18:05:06 -0400 | [diff] [blame] | 335 | break; |
| 336 | default: |
| 337 | break; |
| 338 | } |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 339 | } else if([[tableColumn identifier] isEqualToString:COLUMNID_ENABLE]) { |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 340 | [cell setState:qIdx.data(Qt::CheckStateRole).value<BOOL>()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
| 344 | // ------------------------------------------------------------------------------- |
| 345 | // outlineViewSelectionDidChange:notification |
| 346 | // ------------------------------------------------------------------------------- |
| 347 | - (void)outlineViewSelectionDidChange:(NSNotification *)notification |
| 348 | { |
| 349 | // ask the tree controller for the current selection |
| 350 | if([[treeController selectedNodes] count] > 0) { |
Alexandre Lision | 81c9721 | 2015-06-17 15:51:53 -0400 | [diff] [blame^] | 351 | auto qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 352 | //Update details view |
Alexandre Lision | 81c9721 | 2015-06-17 15:51:53 -0400 | [diff] [blame^] | 353 | auto acc = AccountModel::instance()->getAccountByModelIndex(qIdx); |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 354 | AccountModel::instance()->selectionModel()->setCurrentIndex(qIdx, QItemSelectionModel::ClearAndSelect); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 355 | |
| 356 | switch (acc->protocol()) { |
| 357 | case Account::Protocol::SIP: |
| 358 | NSLog(@"SIP"); |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 359 | [self setupSIPPanels]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 360 | break; |
| 361 | case Account::Protocol::IAX: |
| 362 | NSLog(@"IAX"); |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 363 | [self setupIAXPanels]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 364 | break; |
| 365 | case Account::Protocol::RING: |
Alexandre Lision | 7f3164c | 2015-06-12 11:45:37 -0400 | [diff] [blame] | 366 | [self setupRINGPanels]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 367 | NSLog(@"DRING"); |
| 368 | break; |
| 369 | default: |
| 370 | break; |
| 371 | } |
| 372 | |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 373 | [self.accountDetailsView setHidden:NO]; |
| 374 | } else { |
| 375 | [self.accountDetailsView setHidden:YES]; |
Alexandre Lision | b7ee3ed | 2015-03-20 18:04:35 -0400 | [diff] [blame] | 376 | AccountModel::instance()->selectionModel()->clearCurrentIndex(); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | |
| 380 | #pragma mark - NSMenuDelegate methods |
| 381 | |
| 382 | - (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:(NSInteger)index shouldCancel:(BOOL)shouldCancel |
| 383 | { |
Alexandre Lision | 53428a5 | 2015-03-20 17:59:00 -0400 | [diff] [blame] | 384 | QModelIndex proxyIdx = proxyProtocolModel->index(index, 0); |
| 385 | QModelIndex qIdx = AccountModel::instance()->protocolModel()->index(proxyProtocolModel->mapToSource(proxyIdx).row()); |
Alexandre Lision | 4de68ce | 2015-04-24 18:22:49 -0400 | [diff] [blame] | 386 | [item setTitle:qIdx.data(Qt::DisplayRole).toString().toNSString()]; |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 387 | |
| 388 | return YES; |
| 389 | } |
| 390 | |
| 391 | - (NSInteger)numberOfItemsInMenu:(NSMenu *)menu |
| 392 | { |
Alexandre Lision | 53428a5 | 2015-03-20 17:59:00 -0400 | [diff] [blame] | 393 | return proxyProtocolModel->rowCount(); |
Alexandre Lision | f5fc479 | 2015-03-17 09:15:43 -0400 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | |
| 397 | |
| 398 | @end |