blob: 456d4f4bd44a66f7ec9d55a610a1055a434c6a1b [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 Lision5855b6a2015-02-03 11:31:05 -050030#import "ConversationsViewController.h"
Alexandre Lision8521baa2015-03-13 11:08:00 -040031
Alexandre Lision5855b6a2015-02-03 11:31:05 -050032#import <callmodel.h>
33
34#define COLUMNID_CONVERSATIONS @"ConversationsColumn" // the single column name in our outline view
35
36@interface ConversationsViewController ()
37
38@end
39
40@implementation ConversationsViewController
41@synthesize conversationsView;
42@synthesize treeController;
43
44- (id)initWithCoder:(NSCoder *)aDecoder
45{
46 if (self = [super initWithCoder:aDecoder]) {
47 NSLog(@"INIT Conversations VC");
48 }
49 return self;
50}
51
52
Alexandre Lision5855b6a2015-02-03 11:31:05 -050053- (void)awakeFromNib
54{
55 NSLog(@"awakeFromNib");
56
57 treeController = [[QNSTreeController alloc] initWithQModel:CallModel::instance()];
58
59 [treeController setAvoidsEmptySelection:NO];
60 [treeController setChildrenKeyPath:@"children"];
61
62 [self.conversationsView bind:@"content" toObject:treeController withKeyPath:@"arrangedObjects" options:nil];
63 [self.conversationsView bind:@"sortDescriptors" toObject:treeController withKeyPath:@"sortDescriptors" options:nil];
64 [self.conversationsView bind:@"selectionIndexPaths" toObject:treeController withKeyPath:@"selectionIndexPaths" options:nil];
65
66 NSInteger idx = [conversationsView columnWithIdentifier:COLUMNID_CONVERSATIONS];
67 [[[[self.conversationsView tableColumns] objectAtIndex:idx] headerCell] setStringValue:@"Conversations"];
68}
69
70#pragma mark - NSOutlineViewDelegate methods
71
72// -------------------------------------------------------------------------------
73// shouldSelectItem:item
74// -------------------------------------------------------------------------------
75- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item;
76{
77 return YES;
78}
79
80// -------------------------------------------------------------------------------
81// dataCellForTableColumn:tableColumn:item
82// -------------------------------------------------------------------------------
83- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item
84{
85 NSCell *returnCell = [tableColumn dataCell];
86
87
88 if(item == nil)
89 return returnCell;
90 if ([[tableColumn identifier] isEqualToString:COLUMNID_CONVERSATIONS])
91 {
92
93 NSIndexPath* idx = ((NSTreeNode*)item).indexPath;
94 NSUInteger myArray[[idx length]];
95 [idx getIndexes:myArray];
96
97 NSLog(@"dataCellForTableColumn, indexPath: %lu", (unsigned long)myArray[0]);
98
99 QModelIndex qIdx = CallModel::instance()->index(myArray[0], 0);
100
101 QVariant test = CallModel::instance()->data(qIdx, Qt::DisplayRole);
102 }
103
104 return returnCell;
105}
106
107// -------------------------------------------------------------------------------
108// textShouldEndEditing:fieldEditor
109// -------------------------------------------------------------------------------
110- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
111{
112 if ([[fieldEditor string] length] == 0)
113 {
114 // don't allow empty node names
115 return NO;
116 }
117 else
118 {
119 return YES;
120 }
121}
122
123// -------------------------------------------------------------------------------
124// shouldEditTableColumn:tableColumn:item
125//
126// Decide to allow the edit of the given outline view "item".
127// -------------------------------------------------------------------------------
128- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
129{
130 return NO;
131}
132
133// -------------------------------------------------------------------------------
134// outlineView:willDisplayCell:forTableColumn:item
135// -------------------------------------------------------------------------------
136- (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
137{
138 if ([[tableColumn identifier] isEqualToString:COLUMNID_CONVERSATIONS])
139 {
140 NSIndexPath* idx = ((NSTreeNode*)item).indexPath;
141 NSUInteger myArray[[idx length]];
142 [idx getIndexes:myArray];
143 NSLog(@"array:%@", idx);
144
145 QModelIndex qIdx;
146 if(idx.length == 2)
147 qIdx = CallModel::instance()->index(myArray[1], 0, CallModel::instance()->index(myArray[0], 0));
148 else
149 qIdx = CallModel::instance()->index(myArray[0], 0);
150
151
152 if(qIdx.isValid())
153 cell.title = CallModel::instance()->data(qIdx, Qt::DisplayRole).toString().toNSString();
154 }
155}
156
157// -------------------------------------------------------------------------------
158// outlineViewSelectionDidChange:notification
159// -------------------------------------------------------------------------------
160- (void)outlineViewSelectionDidChange:(NSNotification *)notification
161{
162 // ask the tree controller for the current selection
163 NSLog(@"outlineViewSelectionDidChange!!");
164}
165
166
167@end