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