Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -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 | */ |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame] | 30 | #import "ConversationsVC.h" |
Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 31 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 32 | #import <callmodel.h> |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 33 | #import <QtCore/qitemselectionmodel.h> |
| 34 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 35 | #define COLUMNID_CONVERSATIONS @"ConversationsColumn" // the single column name in our outline view |
| 36 | |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame] | 37 | @interface ConversationsVC () |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 38 | |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 39 | @property QNSTreeController *treeController; |
| 40 | @property (assign) IBOutlet NSOutlineView *conversationsView; |
| 41 | |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 42 | @end |
| 43 | |
Alexandre Lision | 4ba1802 | 2015-04-23 12:17:40 -0400 | [diff] [blame] | 44 | @implementation ConversationsVC |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 45 | @synthesize conversationsView; |
| 46 | @synthesize treeController; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 47 | - (void)awakeFromNib |
| 48 | { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 49 | NSLog(@"INIT Conversations VC"); |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 50 | |
| 51 | treeController = [[QNSTreeController alloc] initWithQModel:CallModel::instance()]; |
| 52 | |
| 53 | [treeController setAvoidsEmptySelection:NO]; |
| 54 | [treeController setChildrenKeyPath:@"children"]; |
| 55 | |
| 56 | [self.conversationsView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil]; |
| 57 | [self.conversationsView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil]; |
| 58 | [self.conversationsView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil]; |
| 59 | |
| 60 | NSInteger idx = [conversationsView columnWithIdentifier:COLUMNID_CONVERSATIONS]; |
| 61 | [[[[self.conversationsView tableColumns] objectAtIndex:idx] headerCell] setStringValue:@"Conversations"]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 62 | |
| 63 | QObject::connect(CallModel::instance(), |
| 64 | &QAbstractItemModel::dataChanged, |
| 65 | [=](const QModelIndex &topLeft, const QModelIndex &bottomRight) { |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 66 | [conversationsView reloadDataForRowIndexes: |
| 67 | [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(topLeft.row(), bottomRight.row() + 1)] |
| 68 | columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, conversationsView.tableColumns.count)]]; |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 69 | }); |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | #pragma mark - NSOutlineViewDelegate methods |
| 73 | |
| 74 | // ------------------------------------------------------------------------------- |
| 75 | // shouldSelectItem:item |
| 76 | // ------------------------------------------------------------------------------- |
| 77 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item; |
| 78 | { |
| 79 | return YES; |
| 80 | } |
| 81 | |
| 82 | // ------------------------------------------------------------------------------- |
| 83 | // dataCellForTableColumn:tableColumn:item |
| 84 | // ------------------------------------------------------------------------------- |
| 85 | - (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 86 | { |
| 87 | NSCell *returnCell = [tableColumn dataCell]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 88 | if(item == nil) |
| 89 | return returnCell; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 90 | return returnCell; |
| 91 | } |
| 92 | |
| 93 | // ------------------------------------------------------------------------------- |
| 94 | // textShouldEndEditing:fieldEditor |
| 95 | // ------------------------------------------------------------------------------- |
| 96 | - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor |
| 97 | { |
| 98 | if ([[fieldEditor string] length] == 0) |
| 99 | { |
| 100 | // don't allow empty node names |
| 101 | return NO; |
| 102 | } |
| 103 | else |
| 104 | { |
| 105 | return YES; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // ------------------------------------------------------------------------------- |
| 110 | // shouldEditTableColumn:tableColumn:item |
| 111 | // |
| 112 | // Decide to allow the edit of the given outline view "item". |
| 113 | // ------------------------------------------------------------------------------- |
| 114 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 115 | { |
| 116 | return NO; |
| 117 | } |
| 118 | |
| 119 | // ------------------------------------------------------------------------------- |
| 120 | // outlineView:willDisplayCell:forTableColumn:item |
| 121 | // ------------------------------------------------------------------------------- |
| 122 | - (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item |
| 123 | { |
| 124 | if ([[tableColumn identifier] isEqualToString:COLUMNID_CONVERSATIONS]) |
| 125 | { |
Alexandre Lision | 33df453 | 2015-03-20 18:25:19 -0400 | [diff] [blame] | 126 | QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 127 | if(qIdx.isValid()) |
| 128 | cell.title = CallModel::instance()->data(qIdx, Qt::DisplayRole).toString().toNSString(); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // ------------------------------------------------------------------------------- |
| 133 | // outlineViewSelectionDidChange:notification |
| 134 | // ------------------------------------------------------------------------------- |
| 135 | - (void)outlineViewSelectionDidChange:(NSNotification *)notification |
| 136 | { |
| 137 | // ask the tree controller for the current selection |
Alexandre Lision | c514805 | 2015-03-04 15:10:35 -0500 | [diff] [blame] | 138 | if([[treeController selectedNodes] count] > 0) { |
| 139 | QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]]; |
| 140 | //Update details view by changing selection |
| 141 | CallModel::instance()->selectionModel()->setCurrentIndex(qIdx, QItemSelectionModel::ClearAndSelect); |
| 142 | } else { |
| 143 | CallModel::instance()->selectionModel()->clearCurrentIndex(); |
| 144 | } |
Alexandre Lision | 5855b6a | 2015-02-03 11:31:05 -0500 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | |
| 148 | @end |