blob: 13aa12ff520b9b3b5384cf3361cd23edef56d550 [file] [log] [blame]
Alexandre Lision8521baa2015-03-13 11:08:00 -04001/*
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 Lision4ba18022015-04-23 12:17:40 -040030#import "ConversationsVC.h"
Alexandre Lision8521baa2015-03-13 11:08:00 -040031
Alexandre Lision5855b6a2015-02-03 11:31:05 -050032#import <callmodel.h>
Alexandre Lisionc5148052015-03-04 15:10:35 -050033#import <QtCore/qitemselectionmodel.h>
34
Alexandre Lision5855b6a2015-02-03 11:31:05 -050035#define COLUMNID_CONVERSATIONS @"ConversationsColumn" // the single column name in our outline view
36
Alexandre Lision4ba18022015-04-23 12:17:40 -040037@interface ConversationsVC ()
Alexandre Lision5855b6a2015-02-03 11:31:05 -050038
Alexandre Lisionc5148052015-03-04 15:10:35 -050039@property QNSTreeController *treeController;
40@property (assign) IBOutlet NSOutlineView *conversationsView;
41
Alexandre Lision5855b6a2015-02-03 11:31:05 -050042@end
43
Alexandre Lision4ba18022015-04-23 12:17:40 -040044@implementation ConversationsVC
Alexandre Lision5855b6a2015-02-03 11:31:05 -050045@synthesize conversationsView;
46@synthesize treeController;
Alexandre Lision5855b6a2015-02-03 11:31:05 -050047- (void)awakeFromNib
48{
Alexandre Lisionc5148052015-03-04 15:10:35 -050049 NSLog(@"INIT Conversations VC");
Alexandre Lision5855b6a2015-02-03 11:31:05 -050050
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 Lisionc5148052015-03-04 15:10:35 -050062
63 QObject::connect(CallModel::instance(),
64 &QAbstractItemModel::dataChanged,
65 [=](const QModelIndex &topLeft, const QModelIndex &bottomRight) {
Alexandre Lisionc5148052015-03-04 15:10:35 -050066 [conversationsView reloadDataForRowIndexes:
67 [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(topLeft.row(), bottomRight.row() + 1)]
68 columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, conversationsView.tableColumns.count)]];
Alexandre Lisionc5148052015-03-04 15:10:35 -050069 });
Alexandre Lision5855b6a2015-02-03 11:31:05 -050070}
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 Lision5855b6a2015-02-03 11:31:05 -050088 if(item == nil)
89 return returnCell;
Alexandre Lision5855b6a2015-02-03 11:31:05 -050090 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 Lision33df4532015-03-20 18:25:19 -0400126 QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)];
Alexandre Lision5855b6a2015-02-03 11:31:05 -0500127 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 Lisionc5148052015-03-04 15:10:35 -0500138 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 Lision5855b6a2015-02-03 11:31:05 -0500145}
146
147
148@end